Skip to content

gh-153569: simplify tokenizer state and source storage - #156484

Draft
pablogsal wants to merge 16 commits into
python:mainfrom
pablogsal:gh-153569-tokenizer-validation-tools-clean
Draft

gh-153569: simplify tokenizer state and source storage#156484
pablogsal wants to merge 16 commits into
python:mainfrom
pablogsal:gh-153569-tokenizer-validation-tools-clean

Conversation

@pablogsal

@pablogsal pablogsal commented Aug 27, 2026

Copy link
Copy Markdown
Member

The tokenizer was keeping several copies of the same positions and a fixed 150-entry mode array in every tokenizer. F- and t-string expressions and comments now use source spans, while their modes live in a small stack that grows only for deeply nested strings. Each mode owns its comment spans, so nesting no longer needs a second stack kept in sync. Prefix handling also uses one enum for f-, t-, and raw strings, so the lexer no longer reconstructs that state from token bytes.

Prepared input is normalized once and stored in one buffer. The reader splits it directly, keeps streamed f- and t-strings in the active buffer, and owns pointer relocation. Line-based tokenizer errors use the current line even while a formatted string keeps a wider buffer. This removes the per-line tables, implicit-newline bitset, cursor and buffer helpers, source aliases, duplicated reader counters, and the extra parser error state. This follows #156482 as the next part of #153569.

Comment thread Modules/_xxtestfuzz/fuzzer.c Outdated
}

static int
fuzz_tokenizer(const char *data, size_t size)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move it to python/library-fuzzers (yes, name is a little misleading). We aren't adding anything to _xxtestfuzz as we are planning to move it all to the repository.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pablogsal a little ping FYI, since I see you're working on this.

@pablogsal pablogsal reopened this Aug 27, 2026
@pablogsal

Copy link
Copy Markdown
Member Author

Do not review until #156482 lands.

@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from 5505010 to 68400fb Compare August 28, 2026 18:40
@pablogsal pablogsal changed the title gh-153569: add tokenizer validation tools gh-153569: move f-string state to source spans Aug 28, 2026
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from 68400fb to 7432a67 Compare August 28, 2026 19:35
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from bb197e7 to 962c0c5 Compare August 28, 2026 22:44
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-validation-tools-clean branch from 962c0c5 to eae3e33 Compare August 28, 2026 23:48
@pablogsal pablogsal changed the title gh-153569: move f-string state to source spans gh-153569: simplify tokenizer state Aug 29, 2026
@pablogsal pablogsal changed the title gh-153569: simplify tokenizer state gh-153569: simplify tokenizer state and source storage Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants